<?php

class Dichvu_m extends CI_Model {
   
	function get_dichvu(){
		$this->db->where('trang_thai', 1);
		$this->db->order_by('thu_tu', 'ASC');
		$this->db->order_by('ten', 'ASC');
		return $this->db->get('dichvu')->result();
	}
	
	function dang_ky_dich_vu($data){
		$userdata = $this->session->userdata('userdata');
		if($userdata){
			$this->db->where('canhan_id', $userdata['canhan_id']);
			$this->db->delete('canhan_dichvu');
		}
		return 
		$this->db->insert_batch('canhan_dichvu', $data);
		echo $this->db->last_query();die;
	}
	
	function get_dichvu_dangky(){
		$userdata = $this->session->userdata('userdata');
		if($userdata){
			$this->db->select('d.*,cd.catse');
			$this->db->from('canhan cn');
			$this->db->join('canhan_dichvu cd', 'cd.canhan_id=cn.id');
			$this->db->join('dichvu d', 'd.id=cd.dichvu_id');
			$this->db->where('d.trang_thai', 1);
			$this->db->where('cn.id', $userdata['canhan_id']);
			$this->db->order_by('d.ten', 'ASC');
			return 
			$this->db->get()->result();
			echo $this->db->last_query();die;
		}
		return false;
	}
	
	function get_dichvu_dangky_by_canhan_id($canhan_id){
		$this->db->select('d.*,cd.catse');
		$this->db->from('canhan cn');
		$this->db->join('canhan_dichvu cd', 'cd.canhan_id=cn.id');
		$this->db->join('dichvu d', 'd.id=cd.dichvu_id');
		$this->db->where('d.trang_thai', 1);
		$this->db->where('cn.id', $canhan_id);
		$this->db->order_by('cd.thu_tu', 'ASC');
		$this->db->order_by('d.ten', 'ASC');
		return 
		$this->db->get()->result();
		echo $this->db->last_query();die;
	}
}
